﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Meqs.Entity;
using Meqs.Entity.Views;
using Meqs.Logic.Interface;

namespace Meqs.Logic.Implement
{
    public class TeacherEvalHistoryLogic : CommonLogic<TeacherEvalHistory, int>, ITeacherEvalHistoryLogic
    {
        #region Implementation of ICommonLogic<TeacherEvalHistory, int>

        /// <summary>
        /// 创建对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Create(TeacherEvalHistory entity)
        {
            return CreateObject(entity);
        }

        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(TeacherEvalHistory entity)
        {
            return UpdateObject(entity);
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public int Delete(int entityId)
        {
            return DeleteObject(entityId);
        }

        /// <summary>
        /// 删除所有对象
        /// </summary>
        /// <returns></returns>
        public int DeleteAll()
        {
            return DeleteAllObject();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public TeacherEvalHistory FindById(int entityId)
        {
            return FindObjectById(entityId);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount()
        {
            return FindObjectByCount();
        }

        /// <summary>
        /// 检索对象
        /// </summary>
        public IList<TeacherEvalHistory> FindAll()
        {
            return FindAllObject();
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount(Hashtable table)
        {
            return FindObjectByCount(table);
        }

        /// <summary>
        /// 检索对象
        /// </summary>
        public IList<TeacherEvalHistory> FindAll(Hashtable table)
        {
            return FindObject(table);
        }

        #endregion

        public int UpdateStatus(Hashtable ht)
        {
            try
            {
                string statementName = "TeacherEvalHistory.UpdateStatus";
                return ExecuteUpdate(statementName, ht);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        /// <summary>
        /// 获取当前评价状态
        /// </summary>
        public IList<TeacherEvalState> GetState(int schoolYear, int term, String schoolMark, IList<int> teacherList, int evalId)
        {
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", schoolMark);
            ht.Add("Year", schoolYear);
            ht.Add("Term", term);
            ht.Add("IDList", teacherList);
            ht.Add("EvalID", evalId);
            IList<TeacherEvalState> result = this.ExecuteQueryForList<TeacherEvalState>("TeacherEvalHistory.GetState", ht);
            return result;
        }

        /// <summary>
        /// 获取当前评价状态
        /// </summary>
        public IList<TeacherEvalState> GetState(int schoolYear, int term, String schoolMark, IList<int> teacherList, int evalId,int managerId)
        {
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", schoolMark);
            ht.Add("Year", schoolYear);
            ht.Add("Term", term);
            ht.Add("IDList", teacherList);
            ht.Add("EvalID", evalId);
            ht.Add("ManagerID", managerId);
            IList<TeacherEvalState> result = this.ExecuteQueryForList<TeacherEvalState>("TeacherEvalHistory.GetState", ht);
            return result;
        }

        /// <summary>
        /// 获取评价历史记录
        /// </summary>
        /// <param name="schoolYear"></param>
        /// <param name="term"></param>
        /// <param name="causeID"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public TeacherEvalHistory GetHistoryRecordByTerm(int schoolYear, int term, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("Year", schoolYear);
            ht.Add("Term", term);
            ht.Add("SchoolMark", schoolMark);

            return FindCustomerByID<TeacherEvalHistory>("TeacherEvalHistory.GetHistoryRecordByTerm", ht);
        }

        /// <summary>
        /// 获取评价历史记录
        /// </summary>
        /// <param name="schoolYear"></param>
        /// <param name="term"></param>
        /// <param name="causeID"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public TeacherEvalHistory GetHistoryRecordByTerm(int historyId,int schoolYear, int term, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("historyId", historyId);
            ht.Add("Year", schoolYear);
            ht.Add("Term", term);
            ht.Add("SchoolMark", schoolMark);

            return FindCustomerByID<TeacherEvalHistory>("TeacherEvalHistory.GetHistoryRecordByTerm", ht);
        }

        public IList<StupidDemand> MakeAStupidDemand(int schoolYear, int term, int teacherID, string schoolMark)
        { 
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", schoolMark);
            ht.Add("TeacherID", teacherID);
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);

            return ExecuteQueryForList<StupidDemand>("TeacherEvalHistory.MakeAStupidDemand", ht);
        }
    }
}
